/*
 * Created on 2007-9-4
 *
 * TODO To change the template for this generated file go to
 * Window - Preferences - Java - Code Style - Code Templates
 */
package com.tongji.quickCRUDQ.webapp.action;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.springframework.web.servlet.ModelAndView;
import org.springframework.web.servlet.mvc.multiaction.MultiActionController;

import com.tongji.quickCRUDQ.dao.jdbc.ColumnDao;
import com.tongji.quickCRUDQ.dao.jdbc.CommonDao;
import com.tongji.quickCRUDQ.dao.jdbc.TableDao;
import com.tongji.quickCRUDQ.define.Row;
import com.tongji.quickCRUDQ.define.Table;
import com.tongji.quickCRUDQ.util.StringUtil;

/**
 * @author Administrator
 *
 * TODO To change the template for this generated type comment go to
 * Window - Preferences - Java - Code Style - Code Templates
 */
public class TestTagController extends MultiActionController {
    private final Log log = LogFactory.getLog(this.getClass());
    private CommonDao commonDao;
    private ColumnDao columnDao;
    private TableDao  tableDao;
	/**
	 * @return Returns the columnDao.
	 */
	public ColumnDao getColumnDao() {
		return columnDao;
	}
	/**
	 * @param columnDao The columnDao to set.
	 */
	public void setColumnDao(ColumnDao columnDao) {
		this.columnDao = columnDao;
	}
	/**
	 * @return Returns the dao.
	 */
	public CommonDao getCommonDao() {
		return commonDao;
	}
	/**
	 * @param dao The dao to set.
	 */
	public void setCommonDao(CommonDao dao) {
		this.commonDao = dao;
	}
	/**
	 * @return Returns the tableDao.
	 */
	public TableDao getTableDao() {
		return tableDao;
	}
	/**
	 * @param tableDao The tableDao to set.
	 */
	public void setTableDao(TableDao tableDao) {
		this.tableDao = tableDao;
	}
	
	public ModelAndView testTag(HttpServletRequest request,HttpServletResponse response){
		String tableName=StringUtil.NVL(request.getParameter("tableName"),"");
		Table table=tableDao.getTable(tableName);
		List columns=columnDao.getColumnList(tableName);
		Row row=new Row();
		row.addColumnList(columns);
	    List data=commonDao.templateSelect(row,null);
	    
	    String tableName2="TABLE_DEF";
		Table table2=tableDao.getTable(tableName2);
		List columns2=columnDao.getColumnList(tableName2);
		Row row2=new Row();
		row2.addColumnList(columns2);
	    List data2=commonDao.templateSelect(row2,null);
	    
		Map model=new HashMap();
		model.put("tableName1",table);
		model.put("listName1",data);
		model.put("rowName1",row);
		model.put("title1",table.getTitle());
		
		model.put("tableName2",table2);
		model.put("listName2",data2);
		model.put("rowName2",row2);
		model.put("title2",table2.getTitle());
		
		return new ModelAndView("quick/testTag","model",model);	 
	}

}
